package com.nj.liandi.gulimall.seckill.scheduled;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * description: 测试定时任务
 * date: 2021/11/9 15:41
 * author: maizj
 * version: 1.0
 */
//@EnableAsync//以异步执行
@Component
//@EnableScheduling//开启定时任务
public class HelloSchedule {
    public static  final Logger logger = LoggerFactory.getLogger(HelloSchedule.class);

    /** description: spring中定时任务由六位组成,不允许第七位的年,在周位置,1-7对应的是周一到周日
     * 定时任务不应该阻塞.默认是阻塞的
     *         1)可以让业务运行以异步的方式,自己提交到线程池执行
     *         2)支持定时任务线程池,改变自动配置的TaskSchedulingAutoConfiguration线程数,
     *          但是这个会因为版本问题,出现bug,容易失效
     *         3)让定时任务以异步执行
     *
     * version: 1.0
     * date: 2021/11/9 15:54
     * */
    @Async
//    @Scheduled(cron = "* * * * * ?")
    public void hello() throws InterruptedException {
        logger.info("执行了定时任务....");
        Thread.sleep(3000);
    }
}
